package com.heima.behavior.listener;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.dto.FollowBehaviorDto;
import com.heima.behavior.service.IApFollowBehaviorService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @Author WSJ
 * @Date 2022-03-17-19:11
 * @Version 1.0 （版本号）
 */
@Service
public class FollowListener {
    @Autowired
    private IApFollowBehaviorService followBehaviorService;
    @KafkaListener(topics = "${topic.followBehaviorTopic}")
    public void followListen(ConsumerRecord<String, String> record) {
        String json = record.value();
        if (!StringUtils.isEmpty(json)) {
            FollowBehaviorDto followBehaviorDto = JSON.parseObject(json, FollowBehaviorDto.class);
            followBehaviorService.saveFollow(followBehaviorDto);
        }


    }
}
